/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uy.com.csi.gestpro.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 *
 * @author ehuamani
 */
public class PostgresConectorJdbc {
    private static Connection CONEXION;
    private static boolean IS_INSTANCE;
    
    static {
        CONEXION=null;
        IS_INSTANCE=false;
    }
    
    public static boolean conectar() throws ClassNotFoundException, SQLException {
        String url = "jdbc:postgresql://"+DefaultConfiguration.IP+
                ":"+DefaultConfiguration.PUERTO+
                "/"+DefaultConfiguration.INSTANCIA;
        
        String cadenaConexion = "org.postgresql.Driver";
        Class.forName(cadenaConexion);
        CONEXION = DriverManager.getConnection(url, DefaultConfiguration.USUARIO, DefaultConfiguration.PASSWORD);
        if (CONEXION != null) {
            return true;
        } else {
            return false;
        }
    }
    
    public static Connection getConexion() throws ClassNotFoundException, SQLException {
        return CONEXION;
    }
    
    public static void cerrarConexion() throws SQLException {
        CONEXION.close();
    }
    
    public static boolean isInstance() {
        return IS_INSTANCE;
    }

    public static void setInstance(boolean instance) {
        IS_INSTANCE = instance;
    }
}
